<template>
	<!-- 钻机信息查询 -->
	<view class="container">
		<empty-data tipText="没有钻机信息" v-if="drillDatas.length === 0"></empty-data>
		<view v-else>
			<block v-for="(item,index) in drillDatas" :key="index">
				<view class="white-bg z-font-lg u-padding-40 z-b-r u-flex u-row-between u-margin-bottom-20">
					<view class="u-flex-1">
						<view>钻机编号：{{item.drill_id}}</view>
						<view>钻机价格：{{item.drill_price | $_formattingMoney}}</view>
						<view>购买日期：{{item.drill_buy_date}}</view>
						<view>
							<u-collapse>
								<u-collapse-item title="维修记录">
									<view class="u-flex u-margin-bottom-20 u-margin-left-20" v-for="(item1,iW) in item.maintain_record" :key="iW">
										<view class="u-flex-1">{{ item1.maintainParts }}</view>
										<view class="u-margin-left-20 u-margin-right-10">{{ item1.maintainDate }}</view>
									</view>
								</u-collapse-item>
							</u-collapse>
						</view>
					</view>
					<view class="u-margin-right-10 u-margin-left-20" style="color: #2979ff;" @click="drillUpdate(item._id)"><u-icon name="edit-pen"></u-icon>编辑</view>
				</view>
			</block>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	import {mapState} from "vuex";
	export default {
		data() {
			return {
				drillDatas:[]
			}
		},
		onLoad() {
			this.getDrillData();
		},
		computed:{
			...mapState({
				token:"token",
				pm_company:"pm_company"
			})
		},
		methods: {
			async getDrillData(){
				let {token,pm_company} = this;
				this.$loading("正在加载");
				// 获取当前pm所属公司的钻机信息。
				let res = await this.$network({
					api:"main",
					data:{
						action:"disposeData/getDrillInfoByPmCompany",
						data:{token,pm_company}
					}
				})
				
				uni.hideLoading();
				if(res.status === 0){
					this.drillDatas = res.data;
					// console.log(this.drillDatas);
				} else {
					this.$refs.uTips.show({
						title: '没有钻机信息',
						type: 'error'
					})
				}
			},
			drillUpdate(id){
				uni.navigateTo({
					url:`../pm-add-drill/pm-add-drill?drillID=${id}`
				})
			}
		}
	}
</script>

<style>

</style>
